﻿using Microsoft.Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ldhWebApiWpf
{
    public class CheckUkeyMiddleware : OwinMiddleware
    {
        public CheckUkeyMiddleware(OwinMiddleware next) : base(next) { }

        public async override Task Invoke(IOwinContext context)
        {
            if (context.Request.Headers.ContainsKey("U-Apikey"))
            {
                if (context.Request.Headers["U-ApiKey"] == "111")
                {
                    await Next.Invoke(context);
                    return;
                }
            }
            context.Response.StatusCode = 404;
            await Task.FromResult<Object>(null);
        }
    }
}
